package com.yunhai.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.model.entity.sys.SysNoticeMessageEntity;
import com.yunhai.model.vo.sys.SysNoticeMessageVo;
import com.yunhai.system.service.SysNoticeMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/notice/message")
public class NoticeMessageController {
    @Autowired
    private SysNoticeMessageService noticeMessageService;

    @GetMapping("/pagination")
    public Ret getNoticeMessagePagination(
        PaginationVo paginationVo) throws Exception {
        IPage page = noticeMessageService.getNoticeMessagePagination(paginationVo);
        return Ret.toPage(page);
    }

    @PostMapping
    public Ret addNoticeMessage(@RequestBody SysNoticeMessageVo sysNoticeMessageVo)  throws Exception {
        noticeMessageService.addNoticeMessage(sysNoticeMessageVo);
        return Ret.ok();
    }

    @PutMapping
    public Ret updateNoticeMessage(@RequestBody SysNoticeMessageVo sysNoticeMessageVo)  throws Exception {
        noticeMessageService.updateNoticeMessage(sysNoticeMessageVo);
        return Ret.ok();
    }


    @PostMapping("/batchRemove")
    public Ret batchRemoveNoticeMessage( @RequestBody List<Long> ids ) throws Exception {

        noticeMessageService.batchRemoveNoticeMessage(ids);
        return Ret.ok();
    }

    @GetMapping("/{id}")
    public Ret<SysNoticeMessageEntity> getNoticeMessageDetail(@PathVariable Long id) throws Exception {
        SysNoticeMessageEntity detail = noticeMessageService.getNoticeMessageDetail(id);
        return Ret.ok(detail);
    }


}
